﻿@model RTW.OA.Areas.Personal.Models.AddressViewModel
@{
    ViewBag.Title = "ShowGroup";
    Layout = "~/Views/Shared/_LayoutBase.cshtml";
}


<div id="groupEdit">
    <div class="from-content">
        <div class="gname">
            <div class="form-group">
                <div class="controls" style="margin-top:30px; margin-left:0px; padding-left:0px;">
                    <label class="col-sm-2 control-label" for="zm" id="bj">编辑组名：</label>
                    <div class="col-sm-4">
                        @if (Model.Address_Group == null)
                        {
                            <input type="text" class="form-control" id="groupname" value="默认组" readonly />
                            @Html.HiddenFor(m => m.Address_Group.GROUP_ID)
                        }
                        else
                        {
                            @Html.EditorFor(m => m.Address_Group.GROUP_NAME, new { htmlAttributes = new { @class = "input txt form-control", datatype = "*", nullmsg = " ", errormsg = " ", sucmsg = " " } })
                            @Html.HiddenFor(m => m.Address_Group.GROUP_ID)
                            @Html.HiddenFor(m => m.Address_Group.USER_ID)
                        }
                    </div>
                    <span class="red" id="pp">(必填项)</span>
                    <button type="button" class="btn btn-info" style="width:120px;display:none" id="share1" onclick="show_share()">共享</button>
                </div>
            </div>
        </div>

        <div style="width:100%;margin-top: 10px;height:auto;">
            <div style="width:543px;margin-left: 90px;">
                <div style="width:200px; float:left">
                    <div style="width:200px; text-align:center;">已选成员</div>
                    <div style="width:200px; background-color:#f8f8f8;">
                        <select id="select1" name="select1" ondblclick="func_move('select1', 'select2');" style="width:200px;height:200px;padding-left: 30px;" multiple="multiple"></select>
                    </div>
                    <div style="width:200px; text-align:center; margin-top: 5px;"><button type="button" class="btn" onclick="func_select_all('select1');">全选</button></div>
                </div>

                <div style="width:143px;height:250px; float:left;line-height:250px; position:relative;">
                    <button type="button" style="position:absolute;top:30%;left:25%;" class="btn btn-success" onclick="func_move('select2', 'select1');"><i class="icon-arrow-left icon-white"></i>添加</button>
                    <button type="button" style="position:absolute;top:50%;left:25%" class="btn btn-danger" onclick="func_move('select1', 'select2');"><i class="icon-arrow-right icon-white"></i>移除</button>
                </div>

                <div style="width:200px; float:left">
                    <div style="width:200px; text-align:center;">备选成员</div>
                    <div style="width:200px;background-color:#f8f8f8;">
                        <select id="select2" name="select2" ondblclick="func_move('select2', 'select1');" style="width:200px;height:200px;padding-left: 30px;" multiple="multiple"></select>
                    </div>
                    <div style="width:200px; text-align:center;margin-top: 10px;"><button type="button" class="btn" onclick="func_select_all('select2');">全选</button></div>
                </div>
                <div style="clear:both; width:480px; text-align:center; padding-top:10px;"><p><span style="color:#F00;">注：</span>点击条目时，可以组合CTRL或SHIFT键进行多选！</p></div>
            </div>
        </div>

        <div id="show_share" style="width:100%;clear:both;padding-top:20px; display:none;border-top:1px #CCCCCC solid">
            <div class="control-group" style="height:150px;">
                <label class="control-label" for="yx">共享时间：</label>
                <div class="controls" style="margin-bottom:30px; width:480px; ">
                    <input type="text" id="share_start" name="share_start" style="width:180px;" size="20" maxlength="19" value="" title="开始时间" onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})">&nbsp;至&nbsp;
                    <input type="text" id="share_end" name="share_end" style="width: 180px;" size="20" maxlength="19" value="" title="结束时间" onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',minDate:'#F{$dp.$D(\'share_start\')}'})"><br>
                    <font color="red"><b>注：</b></font>如果开始时间为空，视为立即开始共享；如果结束时间为空，视为永久共享！
                </div>
                <label class="control-label" for="yx">共享范围：</label>
                <div class="controls" style="margin-bottom:30px; width:480px;">
                    <input type="hidden" name="to_id" id="to_id" value="">
                    <textarea rows="3" class="SmallStatic" name="to_name" id="to_name" style="width:270px;" wrap="yes" readonly=""></textarea>
                    <a href="javascript:;" class="orgAdd" onclick="SelectUser('10', '', 'to_id', 'to_name')">添加</a>
                    <a href="javascript:;" class="orgClear" onclick="ClearUser('to_id', 'to_name')">清空</a><br>
                    <input type="checkbox" style="width:20px; margin-bottom:6px;" name="sms"><label style="display:inline;">向共享人员发送事务提醒</label>
                </div>

                <label class="control-label" for="yx">共享内容：</label>
                <div class="controls" style="margin-bottom:30px; width:480px;">
                    <input type="hidden" name="add_id_str" id="add_id_str" value="">
                    <input type="hidden" name="FLD_STR" value="">
                    <input type="hidden" name="GROUP_ID" value="0">
                    <textarea name="add_name_str" id="add_name_str" rows="3" style="overflow-y:auto;width:270px;" class="SmallStatic" wrap="yes" readonly=""></textarea>
                    <a href="javascript:;" class="orgAdd" onclick="SelectAdd('add_id_str','add_name_str','')">添加</a>
                    <a href="javascript:;" class="orgClear" onclick="ClearUser('add_id_str', 'add_name_str')">清空</a>&nbsp;&nbsp;<br><br>
                </div>
            </div>
        </div>
    </div>

    <div class="from-footer">
        <div class="btn-wrap" style="position: fixed;" onclick="savefrom()">
            <a class="btn btn-sm btn-primary radius">
                <i class="iconfont icon-save"></i>
                提交保存
            </a>
            <a class="btn btn-sm btn-warning radius" onclick="parent.closeTab('6202')">
                <i class="iconfont icon-fanhui"></i>
                取消关闭
            </a>
        </div>
    </div>
</div>

@section scripts{
    <script src="@Url.Content("~/Content/JS/common/WdatePicker/WdatePicker.js")"></script>
    <script type="text/javascript" charset="utf-8" src="@Url.Content("~/Content/JS/common/jquery/Validform_v5.3.2_min.js")"></script>
    <script type="text/javascript" charset="utf-8" src="@Url.Content("~/Content/JS/common/artdialog/dialog-plus-min.js")"></script>
    <script type="text/javascript" charset="utf-8" src="@Url.Content("~/Content/JS/common/webuploader/webuploader.min.js")"></script>
    <script type="text/javascript" charset="utf-8" src="@Url.Content("~/Content/editor/ueditor.config.js")"></script>
    <script type="text/javascript" charset="utf-8" src="@Url.Content("~/Content/editor/ueditor.all.min.js")"></script>
    <script type="text/javascript" charset="utf-8" src="@Url.Content("~/Content/editor/lang/zh-cn/zh-cn.js")"></script>

    <script src="@Url.Content("~/Content/JS/common/from.js")"></script>
    <script>
        var AddressList = $.parseJSON('@Html.Raw(ViewBag.AddressList)');
        $(document).ready(function () {
            $("#select1").html("");
            $("#select2").html("");
            var groupId = $("#Address_Group_GROUP_ID").val();
            debugger
            if (AddressList.length > 0) {
                $.each(AddressList, function (i, item) {
                    if (groupId != null && groupId != "" && item.GROUP_ID === Number(groupId)) {
                        $("#select1").append($('<option></option>').val(item.ADD_ID).text(item.PSN_NAME));
                    }
                    if (item.GROUP_ID === null) {
                        if (groupId != null && groupId != "") {
                            $("#select2").append($('<option></option>').val(item.ADD_ID).text(item.PSN_NAME));
                        } else {
                            $("#select1").append($('<option></option>').val(item.ADD_ID).text(item.PSN_NAME));
                            $("#select2").append($('<option></option>').val(item.ADD_ID).text(item.PSN_NAME));
                        }
                    }
                });
            }
        });

        //已选成员<-->备选成员 添加/删除
        function func_move(listfrom, listto) {
            var size = $("#" + listfrom + " option").size();
            var selsize = $("#" + listfrom + " option:selected").size();
            if (size > 0 && selsize > 0) {
                $.each($("#" + listfrom + " option:selected"), function (i, own) {
                    $(own).appendTo($("#" + listto));
                });
            }
        }

        //已选成员/备选成员 全选
        function func_select_all(listId) {
            debugger
            var size = $("#" + listId + " option").size();
            if (size > 0) {
                $.each($("#" + listId + " option"), function (i, own) {
                    $(own).prop("selected", true);
                });
            }
        }

        function savefrom() {
            var choosedArr = new Array();
            var unChoosedArr = new Array();
            var groupId = $("#Address_Group_GROUP_ID").val();
            if (groupId != null && groupId != "") {
                var groupName = $("#Address_Group_GROUP_NAME").val();
                var userId = $("#Address_Group_USER_ID").val();
                $("#select1 option").each(function () {
                    choosedArr.push($(this).val());//向已选成员数组中添加元素
                });
                $("#select2 option").each(function () {
                    unChoosedArr.push($(this).val());//向备选成员数组中添加元素
                });
                var choosedIdArr = choosedArr.join(',') + "|" + unChoosedArr.join(',');
                if (choosedIdArr.length <= 1) {
                    layer.msg('请选择一笔资料！', {
                        icon: 1,
                        time: 2000//2s后自动关闭
                    });
                } else {
                    debugger
                    $.ajax({
                        type: "POST",
                        async: false,
                        url: '@Url.Action("AddressGroupReEdit", "Address", new { area = "Personal" })',
                        data: { "choosedIdArr": choosedIdArr, "groupId": groupId, "groupName": groupName, "userId": userId },
                        success: function (data) {
                             layer.msg('保存成功!', {
                                icon: 1,
                                    time: 2000//2s后自动关闭
                            });
                        }
                    });
                }
            }
        }

    </script>
}
